<!-- src/views/SocialPage.vue -->
<script setup>
import { ref } from 'vue';
import ChatRoomItem from '@/components/ChatRoomItem.vue';

// 顶部四个功能项数据
const functionItems = ref([
  {
    name: '好友',
    icon: require('@/assets/images/friend.png'),
    unread: 0
  },
  {
    name: '粉丝',
    icon: require('@/assets/images/fan.png'),
    unread: 0
  },
  {
    name: '点赞',
    icon: require('@/assets/images/like.png'),
    unread: 0
  },
  {
    name: '收藏',
    icon: require('@/assets/images/star.png'),
    unread: 100
  }
]);

// 聊天室列表数据
const chatRooms = ref([
  {
    avatar: require('@/assets/images/record.png'),
    name: 'homie大厅',
    message: '官方聊天室',
    tag: '官方',
    tagType: 'primary'
  },
  {
    avatar: require('@/assets/images/record.png'),
    name: '9999',
    message: '15556',
    tag: '个人',
    tagType: 'primary'
  }
]);
</script>

<template>
  <van-nav-bar :title="$route.name">
    <template #right>
      <van-icon name="search" size="18"/>
    </template>
  </van-nav-bar>

  <div class="social-container">
    <!-- 顶部四个功能入口 -->
    <div class="function-grid">
      <div
          v-for="item in functionItems"
          :key="item.name"
          class="function-item"
      >
        <van-badge :content="item.unread" :show-zero="true">
          <div class="function-icon">
            <img :src="item.icon" />
          </div>
        </van-badge>
        <div class="function-name">{{ item.name }}</div>
      </div>
    </div>

    <!-- 私信按钮 -->
    <div class="message-section">
      <div class="message-icon">
        <img src="@/assets/images/message.png" />
      </div>
      <div class="message-text">私信</div>
    </div>

    <!-- 聊天室列表 -->
    <div class="chat-room-list">
      <ChatRoomItem
          v-for="(room, index) in chatRooms"
          :key="index"
          :avatar="room.avatar"
          :name="room.name"
          :message="room.message"
          :tag="room.tag"
          :tag-type="room.tagType"
      />
    </div>
  </div>
</template>

<style scoped>
.social-container {
  padding: 16px;
  background-color: white;
}

.function-grid {
  display: flex;
  justify-content: space-around;
  margin-bottom: 20px;
}

.function-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.function-icon {
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
}

.function-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.function-name {
  font-size: 14px;
  color: #333;
}

.message-section {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background-color: #f7f8fa;
  border-radius: 8px;
  margin-bottom: 20px;
}

.message-icon {
  width: 24px;
  height: 24px;
  margin-right: 12px;
}

.message-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.message-text {
  font-size: 16px;
  color: #333;
}

.chat-room-list {
  border-radius: 8px;
  overflow: hidden;
}
</style>
